/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package Estacionamento.DAOGenerico;

import ProjetoCompreJa.ClassesBasicas.ClienteCJ;
import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import javax.persistence.Query;
import javax.persistence.TypedQuery;

/**
 *
 * @author Marcos
 * @param <Entidade>
 */
public abstract class DAOGenerico_CJ<Entidade> implements IDAOGenerico_CJ<Entidade> {

    EntityManagerFactory emf;
    EntityManager em;

    public DAOGenerico_CJ() {
        emf = Persistence.createEntityManagerFactory("compreja");
        em = emf.createEntityManager();
    }

    @Override
    public final void Cadastrar(Entidade t) throws Exception {
        try {
            em.getTransaction().begin();
            em.merge(t);
            em.getTransaction().commit();
            emf.close();
        } catch (Exception ex) {
            throw new Exception(ex.getMessage());
        }
    }

    public final void Alterar(Entidade t) throws Exception {
        try {
            em.getTransaction().begin();
            em.merge(t);
            em.getTransaction().commit();
            emf.close();
        } catch (Exception ex) {
            throw new Exception(ex.getMessage());
        }
    }
}
